package com.daffodil.workable.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.PositiveOrZero;
import javax.validation.constraints.Size;

import org.hibernate.annotations.GenericGenerator;

import com.daffodil.core.annotation.Hql;
import com.daffodil.core.annotation.Hql.Logical;
import com.daffodil.core.entity.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * -任务执行计划
 * @author yweijian
 * @date 2022年4月27日
 * @version 1.0
 * @description
 */
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "wok_plan")
public class WorkablePlan extends BaseEntity<String> {
    
    private static final long serialVersionUID = 9915621457181101L;
    
    /** 主键编号 */
    @Id
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid")
    @Column(name = "id")
    private String id;
    
    /** 计划名称 */
    @Column(name = "plan_name", length = 128)
    @Hql(type = Logical.LIKE)
    @NotBlank(message = "计划名称不能为空")
    @Size(min = 1, max = 128, message = "计划名称长度限制为1~128个字符")
    private String planName;
    
    /** 任务编号 */
    @Column(name = "task_id")
    @Hql(type = Logical.EQ)
    private String taskId;
    
    /** 任务名称 */
    @Transient
    private String taskName;
    
    /** 版本号 */
    @Transient
    private String version;
    
    /** 计划状态 */
    @Hql(type = Logical.EQ)
    @Column(name = "status")
    private String status;
    
    /** CRON表达式 */
    @Column(name = "expression")
    private String expression;
    
    /** 计划排序 */
    @Column(name = "order_num")
    @PositiveOrZero(message = "计划排序只能是正整数或零")
    private Long orderNum;
    
    /** 上一次调度时间 */
    @Column(name = "last_ime")
    private Long lastTime;
    
    /** 下一次调度时间 */
    @Hql(type = Logical.LEQ)
    @Column(name = "next_ime")
    private Long nextTime;
    
    /** 创建者 */
    @Column(name = "create_by")
    @Hql(type = Logical.EQ)
    private String createBy;

    /** 创建时间 */
    @Column(name = "create_time")
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /** 更新者 */
    @Column(name = "update_by")
    @Hql(type = Logical.EQ)
    private String updateBy;

    /** 更新时间 */
    @Column(name = "update_time")
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date updateTime;
    
    /** 备注 */
    @Column(name = "remark")
    private String remark;
}
